﻿@using Ext.Net;
@using Ext.Net.MVC;
@using System.Configuration;
@{ var X = Html.X(); }

@X.ResourceManager().Theme((Theme)int.Parse(ConfigurationManager.AppSettings["theme"].ToString()))

@(X.Viewport()
      .Layout(LayoutType.Fit)
      .Border(false)
      .Items(
          X.Panel()
              .Layout(LayoutType.Fit)
              .Border(false)
              .BottomBar(
                  X.Toolbar()
                      .Layout(LayoutType.HBox)
                      .LayoutConfig(new HBoxLayoutConfig { Align = HBoxAlign.Middle, Pack = BoxPack.End })
                      .Items(
                          X.Button().Text("确定").Icon(Icon.Accept).OnClientClick("AddUser"),
                          X.Button().Text("取消").Icon(Icon.Cancel).OnClientClick("CancelAddUser")
                      )
              )
              .Items(
                  X.FormPanel()
                      .BodyStyle("background-color:transparent")
                      .Border(false)
                      .ID("AddUserForm")
                      .Padding(10)
                      .Layout(LayoutType.Table)
                      .LayoutConfig(new TableLayoutConfig { Columns = 2 })
                      .Items(
                          X.TextField().FieldLabel("用户名").ID("txtUserName").MarginSpec("10 10 0 0"),
                          X.TextField().FieldLabel("密码").ID("txtPassWord").MarginSpec("10 10 0 0"),
                          X.TextField().FieldLabel("联系电话").ID("txtTel").MarginSpec("10 10 0 0"),
                          X.TextField().FieldLabel("邮箱").ID("txtEmail").MarginSpec("10 10 0 0"),
                          X.TextField().FieldLabel("QQ").ID("txtQQ").MarginSpec("10 10 0 0"),
                          X.ComboBox().FieldLabel("角色").MarginSpec("10 10 0 0").Editable(false)
                                          .DisplayField("TITLE")
                                          .ValueField("ID")
                                          .EmptyText("请选择...")
                                          .Store(
                                              X.Store().Model(X.Model().Fields(
                                                  new ModelField("ID", ModelFieldType.Int),
                                                  new ModelField("TITLE", ModelFieldType.String))
                                                  ).DataSource(ViewBag.group)
                                          ).ID("cbxGroup").Name("cbxGroup"),
                          X.ComboBox().FieldLabel("所属管理员").MarginSpec("10 10 0 0").Editable(false)
                                          .DisplayField("username")
                                          .ValueField("userid")
                                          .EmptyText("请选择...")
                                          .Store(
                                              X.Store().Model(X.Model().Fields(
                                                  new ModelField("userid", ModelFieldType.Int),
                                                  new ModelField("username", ModelFieldType.String))
                                                  ).DataSource(ViewBag.admin)
                                          ).ID("cbxBelongTo").Name("cbxBelongTo")
                      )

              )
      ))

<script type="text/javascript">
    function AddUser() {

        App.WinAddUser.setLoading(true);

        App.direct.AddUser(
                    serializeJson("AddUserForm"),
                    {
                        success: function (result) {
                            if (result.Result != "OK") {
                                Ext.Msg.alert('信息', result.Message);
                            } else {
                                Ext.Msg.alert('信息', result.Message, function () {
                                    parent.App.WinAddUser.close();
                                    parent.FunctionSearch();
                                });
                            }
                            App.WinAddUser.setLoading(false);
                        },
                        failure: function (error) {
                            Ext.Msg.alert('信息', result.Message);
                            App.WinAddUser.setLoading(false);
                        }
                    }
                );


    }

    function CancelAddUser() {
       
    }
</script>